# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python

class Recipe(recipe.Recipe):
    name = 'gtk-doc-lite'
    version = '1.29'
    stype = SourceType.TARBALL
    tarball_dirname = 'gtk-doc-%(version)s'
    url = 'gnome://gtk-doc/%(maj_ver)s/gtk-doc-%(version)s.tar.xz'
    tarball_checksum = '14578e002496567276d310a62c9ffd6c56ee8806ce5079ffb0b81c4111f586b1'
    # TODO: check license - source files are GPLv2+ and COPYING is GPLv3
    licenses = [License.GPLv2Plus]
    btype = BuildType.CUSTOM

    files_devel = ['bin/gtkdocize', 'share/aclocal/gtk-doc.m4',
                   'share/gtk-doc/data/gtk-doc.make',
                   'share/gtk-doc/data/gtk-doc.notmpl.make']

    def install(self):
        from cerbero.utils import shell
        import shutil
        aclocal_dir = os.path.join(self.config.prefix, 'share', 'aclocal')
        if not os.path.exists(aclocal_dir):
            os.makedirs(aclocal_dir)
        data_dir = os.path.join(self.config.prefix, 'share', 'gtk-doc', 'data')
        if not os.path.exists(data_dir):
            os.makedirs(data_dir)
        bin_dir = os.path.join(self.config.prefix, 'bin')
        if not os.path.exists(bin_dir):
            os.makedirs(bin_dir)
        autotools_dir = os.path.join(self.build_dir, 'buildsystems/autotools')
        shutil.copy(os.path.join(autotools_dir, 'gtk-doc.m4'),
                    os.path.join(aclocal_dir, 'gtk-doc.m4'))
        shutil.copy(os.path.join(autotools_dir, 'gtk-doc.make'),
                    os.path.join(data_dir,  'gtk-doc.make'))
        gtkdocize = os.path.join(self.config.prefix, 'bin', 'gtkdocize')
        shutil.copy(os.path.join(autotools_dir, 'gtkdocize.in'), gtkdocize)
        replacements = {'@PACKAGE@': 'gtk-doc', '@VERSION@': self.version,
                        '@prefix@': self.config.prefix,
                        '@datarootdir@': '${prefix}/share',
                        '@datadir@': '${datarootdir}'}
        shell.replace(gtkdocize, replacements)
        shell.call('chmod +x gtkdocize', os.path.join(self.config.prefix, 'bin'), env=self.env)
